
#ifndef TP_IMAGE_DECODER_H
#define TP_IMAGE_DECODER_H

#include "tp_bitmap.h"

TP_DECL_BEGIN

struct _TpImageDecoder;
typedef struct _TpImageDecoder TpImageDecoder;

typedef TpRet (*TpImageDecoderMatch)(TpImageDecoder* thiz, const char* file);
typedef TpBitmap* (*TpImageDecoderDecode)(TpImageDecoder* thiz, const char* file);
typedef void (*TpImageDecoderDestroy)(TpImageDecoder* thiz);

struct _TpImageDecoder 
{
	TpImageDecoderMatch match;
	TpImageDecoderDecode decode;
	TpImageDecoderDestroy destroy;
};

static inline int tp_image_decoder_match(TpImageDecoder* thiz, const char* file)
{
	if (NULL == thiz || NULL == file) return TP_RET_BADARGS;

	return thiz->match(thiz, file);
}

static inline TpBitmap* tp_image_decoder_decode(TpImageDecoder* thiz, const char* file)
{
	if (NULL == thiz || NULL == file) return NULL;

	return thiz->decode(thiz, file);
}

static inline void tp_image_decoder_destroy(TpImageDecoder* thiz)
{
	if (NULL != thiz && NULL != thiz->destroy)
	{

		thiz->destroy(thiz);
	}
}

void tp_image_decoder_init(void);

TP_DECL_END

#endif /*TP_IMAGE_DECODER_H*/